package lucava.metamodel.java.type;

import java.util.HashMap;
import java.util.Map;
import lucava.metamodel.java.IConfigurableEntity;
import lucava.metamodel.java.MetaPackage;
import lucava.metamodel.java.visitor.IJavaMetaModelVisitor;

public class MetaType implements IConfigurableEntity {

	protected String mName;

	protected MetaPackage mPackage = new MetaPackage();

	protected final Map<String, String> mProperties = new HashMap<String, String>();

	public MetaType(String aName) {
		this.setName(aName);
	}

	public String getName() {
		return mName;
	}

	public void setName(String aName) {
		this.mName = aName;
	}

	public void accept(IJavaMetaModelVisitor aVisitor) {
		aVisitor.visitType(this);
	}

	public boolean isVoid() {
		return false;
	}

	public MetaPackage getPackage() {
		return this.mPackage;
	}

	public void setPackage(MetaPackage aPackage) {
		this.mPackage = aPackage;
	}

	public void setPackage(String aPackageName) {
		this.mPackage.setName(aPackageName);
	}

	public String getCompleteName() {
		String packageName = this.getPackage().getCompleteName();

		if (!packageName.isEmpty()) {
			packageName += ".";
		}

		return packageName + this.getName();
	}

	@Override
	public String getProperty(String aKey) {
		return this.mProperties.get(aKey);
	}

	@Override
	public String getProperty(String aKey, String aDefaultValue) {
		String result = this.getProperty(aKey);
		if (result == null) {
			result = aDefaultValue;
		}
		return result;
	}

	@Override
	public void setProperty(String aKey, String aProperty) {
		this.mProperties.put(aKey, aProperty);
	}

	@Override
	public Map<String, String> getProperties() {
		return this.mProperties;
	}
}
